package com.team11.server.controller.teacher;


import com.team11.server.pojo.dto.*;
import com.team11.server.pojo.dto.vo.AddWorkListVo;
import com.team11.server.pojo.dto.vo.JobAuditListVo;
import com.team11.server.service.IHInformationService;
import com.team11.server.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author pjc
 * @since 2021-06-17
 */
@CrossOrigin
@RestController
@RequestMapping("/teacher")
@Api(tags = "教师接口")
@Validated
public class TeacherHInformationController {

    @Autowired
    private IHInformationService ihInformationService;


    @ApiOperation(value = "作业管理-->下发作业：进行下发作业操作")
    @PostMapping("/addHomework")
    public RespBean addHomework(@Validated AddHomeWork addHomeWork,
                                BindingResult result,
                                @RequestParam("pId") List<Integer> pId,
                                @RequestParam("student") List<String> student,
                                @RequestParam("tJobNumber") String tJobNumber,
                                MultipartFile[] files,
                                HttpServletRequest request) throws Exception {
        if (result.hasErrors()) {
            Map<String,String> err=Result.notNull(result);
            return RespBean.error("", err);
        }
        return ihInformationService.addHomework(addHomeWork, pId, student, tJobNumber, files, request);
    }

    @ApiOperation(value = "作业管理-->下发作业：教师修改作业内容")
    @PostMapping("/updateWork")
    public RespBean updateWork(@Validated AddHomeWork addHomeWork,
                               BindingResult result,
                               @RequestParam("pId") List<Integer> pId,
                               @RequestParam("student") List<String> student,
                               @RequestParam("tJobNumber") String tJobNumber,
                               @RequestParam("hId") Integer hId,
                               MultipartFile[] files,
                               HttpServletRequest request) throws Exception{
        if (result.hasErrors()) {
            Map<String,String> err=Result.notNull(result);
            return RespBean.error("", err);
        }
        return ihInformationService.updateWork(addHomeWork, pId, student, tJobNumber, hId, files, request);
    }

    @ApiOperation(value = "作业管理-->下发作业：教师删除作业")
    @DeleteMapping("/deleteWork")
    public RespBean deleteWork(@RequestParam("hId") Integer hId) {
        return ihInformationService.deleteWork(hId);
    }


    @ApiOperation(value = "作业管理-->下发作业：根据hId获取作业信息（点击编辑作业时用）")
    @GetMapping("/getWorkByHId")
    public List getWorkByHId(@RequestParam("hId") Integer hId) {
        List list = ihInformationService.getWorkByHId(hId);
        return list;
    }

    @ApiOperation(value = "作业管理-->下发作业：教师查看下发的作业(分页)")
    @PostMapping("/getDistributeJobList")
    public RespPageBean getDistributeJobList(@RequestParam(defaultValue = "1") Integer currentPage,
                                             @RequestParam(defaultValue = "10") Integer size,
                                             AddWorkListVo addWorkListvo
    ) {
        return ihInformationService.getDistributeJobList(currentPage, size, addWorkListvo);
    }


    @ApiOperation(value = "作业管理-->作业审核：教师查看已下发作业的任务列表（作业详情）(分页)")
    @PostMapping("/getJobAuditList")
    public RespPageBean getJobAuditList(@RequestParam(defaultValue = "1") Integer currentPage,
                                        @RequestParam(defaultValue = "10") Integer size,
                                        @RequestParam("status") Integer status,
                                        JobAuditListVo jobAuditListVo) {
        return ihInformationService.getJobAuditList(currentPage, size, status, jobAuditListVo);
    }

    @ApiOperation("作业管理-->作业审核：根据hId获取作业任务(只返回作业的信息)")
    @GetMapping("/getWorkTask")
    public WorkTask getWorkTask(@RequestParam("hId") Integer hId) {
        return ihInformationService.getWorkTask(hId);
    }

}
